const axios = require('axios')
const service = axios.create({
  timeout: 60000
})

// request interceptor
service.interceptors.request.use(
  config => {
    config.headers['Content-Type'] = 'application/json'

    return config
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)

service.interceptors.response.use(
  response => {
    const res = response.data
   
    if (res.code == '200' || res.result_code == '0') {
      return res
    } else {
      // console.log('请求出错',response);
      // console.log('请求出错',response.config.url);
      return res
    }
  },
  error => {
    console.log('err' + error) // for debug
    return new Error('系统繁忙,请联系系统管理员查看!')
  }
)

module.exports = {
  service
}
